﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.WebProvider
@{
    ViewBag.Title = "销售商员工列表";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
@model ZBJF.Warranty.Model.SellerEmployee

<ul class="nav nav-tabs">
    <li class="active"><a href="/SellerEmployee/">销售商员工列表</a></li>
</ul>
@*<form id="searchForm" class="breadcrumb form-search">*@
    <div class="breadcrumb form-search">
    <label>关键字</label>
    @Html.TextBox("LikeName", "", new { maxlength = 20, @class = "", placeholder = "员工账号/名称/电话/邮箱/身份证" })
    <label>销售商</label>
    @Html.DropDownList("SellerID", ConvertToSelector.Instance.SellerNameToSelectList(), new { maxlength = 20 })
    <label>
        <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">
    </label>
</div>
@*</form>*@
<div class="table-responsive dataTables_wrapper">
    <label class="Add-R">
        <a id="AddNewRole" class="btn btn-xs btn-primary" data-toggle="modal" href="" onclick="showAddNewAdmin(0)" title="销售商员工">
            <i class="icon-plus-sign bigger-130"></i>
            添加销售商员工
        </a>
    </label>
    <table id="sellersEmployeeList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="100">销售商员工账号</th>
                <th width="100">销售商员工名称</th>
                <th width="100">所属销售商</th>
                <th width="100">员工联系电话</th>
                <th width="100">员工邮箱</th>
                <th width="100">员工身份证</th>
                <th width="80">是否启用</th>
                <th width="80">创建时间</th>
                <th width="100">操作</th>
            </tr>
        </thead>
    </table>
</div>
<div class="modal fade" id="ShowAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    @RenderPage("DisplayTemplates/SellerEmployeeForm.cshtml")
</div>
@section scripts{
    @Scripts.Render("~/Bundles/ImagePreview")
    @Scripts.Render("~/bundles/chosen")
    @Scripts.Render("~/bundles/permission")
    <script type="text/javascript">
        var indexs;
        window.onload = function () {
            $("#shows").hide();
        }
        var isSearch = false;
        $(function () {
            var objTable = $("#sellersEmployeeList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/SellerEmployee/Index",
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "UserAccount" },
                        { "mData": "UserName" },
                        { "mData": "SellersName" },
                        { "mData": "UserPhone" },
                        { "mData": "Email" },
                        { "mData": "CertificateNO" },
                        { "mData": "ID" },
                        { "mData": "CreateTime" },
                        { "mData": "ID" }
                    ],
                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        $('td:eq(7)', nRow).html(aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon);
                        var html = "<a class='Edit-R'  href=\"javascript:ShowEidtDialog(" + aData.ID + ")\" title='编辑'><i class='icon-edit'></i></a>";
                        //html += "<a href=\"javascript:showLayerOpen('设置用户角色','/SellerEmployee/SellerEmployeeRoleMapping?SellerEmployeeID=" + aData.ID + "','500px','200px')\" class=\"Edit-R\" title=\"角色权限编辑\"><i class=\"icon-user green bigger-120\"></i></a>";
                        html += "<a class=\"red Edit-R\" href=\"javascript:ShowResetPSWswDialog('" + aData.ID + "')\" title=\"重置密码\"><i class=\"icon-refresh bigger-130\"></i></a>";
                        html += "<a class='Edit-R' href=\"javascript:UpdateStatus('" + aData.ID + "'," + !aData.IsAvailable + ",'/SellerEmployee/UpdateSellerEmployee','sellersEmployeeList')\" title='" + (aData.IsAvailable ? "禁用" : "启用") + "'>" + (aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                        $('td:eq(9)', nRow).html(html);
                    }
                });
            imgPreview();
        });

        function imgPreview() {
            setTimeout(function () { $("img.preview").preview(); }, 500);
        }

        function showAddNewAdmin(id) {
            document.getElementById("mvcForm").reset(); //清空表单
            $("#div_add_admin_password").css("display", "block");
            $("#ID").val(id);
            $('#ShowAdd').modal();
        }
        function ShowEidtDialog(id) {
            clearForm("mvcForm");
            $.ajax({
                type: "post",
                data: { id: id },
                url: "/SellerEmployee/GetSellerEmployeeInfo",
                success: function (result) {
                    if (result.success) {
                        $("#div_add_admin_password").css("display", "none"); //不可以编辑密码，移除
                        $("#ID").val(id);
                        $("#UserAccount").val(result.result.UserAccount);
                        $("#UserName").val(result.result.UserName);
                        $("#UserPhone").val(result.result.UserPhone);
                        $("#Email").val(result.result.Email);
                        $("#CertificateNO").val(result.result.CertificateNO);
                        $("#SellerId").val(result.result.SellerId);
                        if (result.result.IsAvailable) {
                            $("input[name='IsAvailable']").eq(1).removeAttr("checked");
                            $("input[name='IsAvailable']").eq(0).attr("checked", "checked");
                        } else {
                            $("input[name='IsAvailable']").eq(1).attr("checked", "checked");
                            $("input[name='IsAvailable']").eq(0).removeAttr("checked");
                        }
                        //$("#PidSelect").html($("#ParentOrganizationId"));
                        //$("#ParentOrganizationId").chosen();;
                        $('#ShowAdd').modal();
                    } else {
                        layer.alert(result.message);
                    }
                },
                error: function (error) {
                    console.log(error.responseText);
                }
            });
        }
        function RestPassWord(id, password) {
            $.ajax({
                type: "post",
                data: { id: id, newPassWord: password },
                url: "/SellerEmployee/RestPassWord",
                success: function (result) {
                    if (result.success) {
                        var index = layer.alert(result.message, {
                            yes: function () {
                                reloadTable("sellersEmployeeList");
                                layer.close(index);
                            }
                        });
                    } else {
                        layer.alert(result.message);
                    }
                }
            });
        }
        function ShowResetPSWswDialog(id) {
            layer.prompt("请输入新的密码", function (result) {
                if (result == null) {

                }
                else if (result == "" || result.length < 6) {
                    var index = layer.alert(result.message, {
                        yes: function () {
                            layer.alert("密码不要小于六位");
                            ShowResetPSWswDialog(id);
                            layer.close(index);
                        }
                    });
                } else {
                    RestPassWord(id, result);
                }
            });
        }
        function search() {
            /*给查询对象赋值*/
            queryParamList.LikeName = $("#LikeName").val().trim();
            queryParamList.SellerId = $("#SellerID").val();
            $("#sellersEmployeeList").dataTable().fnDraw();
            imgPreview();
        }
    </script>
}
